#include "stm32f10x.h"                  // Device header
#include "OLED.h"
#include "AD.h"
#include "Delay.h"

uint16_t AD_value;
float Vol0, Vol1, Vol2, Vol3;
uint16_t AD0, AD1, AD2, AD3;

int main(void)
{
	OLED_Init();
	AD_Init();
	OLED_ShowString(1,1,"Voltage:0.00V");
	OLED_ShowString(2,1,"Voltage:0.00V");
	OLED_ShowString(3,1,"Voltage:0.00V");
	OLED_ShowString(4,1,"Voltage:0.00V");
	while(1)
	{
		AD0 = AD_GetValue(ADC_Channel_7);
		AD1 = AD_GetValue(ADC_Channel_1);
		AD2 = AD_GetValue(ADC_Channel_2);
		AD3 = AD_GetValue(ADC_Channel_3);
		Vol0 = (3.3 / 4095) * (float)AD0;
		Vol1 = (3.3 / 4095) * (float)AD1;
		Vol2 = (3.3 / 4095) * (float)AD2;
		Vol3 = (3.3 / 4095) * (float)AD3;
		OLED_ShowNum(1, 9, Vol0, 1);
		OLED_ShowNum(1, 11, (uint16_t)(Vol0 * 100) % 100, 2);
		
		OLED_ShowNum(2, 9, Vol1, 1);
		OLED_ShowNum(2, 11, (uint16_t)(Vol1 * 100) % 100, 2);
		
		OLED_ShowNum(3, 9, Vol2, 1);
		OLED_ShowNum(3, 11, (uint16_t)(Vol2 * 100) % 100, 2);
		
		OLED_ShowNum(4, 9, Vol3, 1);
		OLED_ShowNum(4, 11, (uint16_t)(Vol3 * 100) % 100, 2);
		Delay_ms(100);
	}
}
